package com.itheima.controller;

import com.itheima.common.Code;
import com.itheima.common.MessageConstant;
import com.itheima.common.Result;
import com.itheima.dto.DishDTO;
import com.itheima.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ding
 * @version 1.0
 * @description: TODO 菜品管理
 * @date 2022/6/5 14:48
 */
@RestController
@RequestMapping("/dish")
public class DishController {
    @Autowired
    private DishService dishService;


    @GetMapping("/list")
    public Result findByCategoryId(@RequestParam(value = "categoryId",required = false) Long categoryId,
                                   @RequestParam(value = "name",required = false) String name){
        // List<Dish> dishList = dishService.findByCategoryId(categoryId,name);
        List<DishDTO> dishList = dishService.findByCategoryId(categoryId,name);
        if (dishList == null){
            dishList = new ArrayList<>();
        }
        return new Result(Code.OK,MessageConstant.DISH_GET_SUCCESS,dishList);
    }

}
